package com.cy3;
/*
用于测试attaylist嵌套hashmap集合
 */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ArrayListIncludeHashMapDemo {
    public static void main(String[] args) {
        ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
        HashMap<String, String> hm = new HashMap<>();
        hm.put("陈勇", "袁湘");
        hm.put("美女", "帅哥");
        arrayList.add(hm);
        HashMap<String, String> hm1 = new HashMap<>();
        hm1.put("林青霞", "王祖贤");
        hm1.put("周瑜", "大乔");
        arrayList.add(hm1);
        HashMap<String, String> hm2 = new HashMap<>();
        hm2.put("凌统", "浦沅");
        hm2.put("甄姬", "曹丕");
        arrayList.add(hm2);
        //遍历方式1
        for (HashMap<String, String> stringStringHashMap : arrayList) {
            Set<String> strings = stringStringHashMap.keySet();
            for (String string : strings) {
                System.out.println(string + "," + stringStringHashMap.get(string));
            }
        }
        System.out.println("-----------------");
        //遍历方式2
        for (HashMap<String, String> stringStringHashMap : arrayList) {
            Set<Map.Entry<String, String>> entries = stringStringHashMap.entrySet();
            for (Map.Entry<String, String> entry : entries) {
                System.out.println(entry.getKey() + "," + entry.getValue());
            }
        }
    }
}
